package com.tarena.sentinel.study.demo02.service;

import com.alibaba.csp.sentinel.Entry;
import com.alibaba.csp.sentinel.SphU;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.tarena.sentinel.study.demo02.handler.HelloServiceBlockHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class HelloService {
    @SentinelResource(value="sayHi",
            blockHandler = "blockHandle",
            blockHandlerClass = HelloServiceBlockHandler.class,
            fallback = "fallHandle")
    public String sayHi(String name) {
        int a=1/0;
        return "hello sentinel i am "+name;
    }
    public String fallHandle(String name,Throwable e){
        return "咋回事,没限流还有其他异常";
    }
    /*//处理的时熔断和限流的降级逻辑
    public String blockHandle(String name, BlockException e){
        log.info("当前访问的方法 正在处理降级逻辑",e);
        return "sayHi方法 被sentinel限制流量了";
    }*/
}
